﻿package mortal.game.view.platform
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import fl.data.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.yyZiZuan.*;

    public class PlatformVerificModule extends BaseWindow
    {
        private var _bg:GImageBitmap;
        private var _verificBtn:GLoadingButton;
        private var _getGiftBtn:GLoadingButton;
        private var _giftList:GTileList;
        private var _textInput:GTextInput;
        public static var platformData:PlatformVerificShowData;
        public static const extend:int = 4;

        public function PlatformVerificModule()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_1:int = 0;
            super.createDisposedChildrenImpl();
            if (platformData)
            {
                setSize(platformData.size.x, platformData.size.y);
                title = platformData.title;
                this._bg = UIFactory.gImageBitmap(platformData.bgResName, platformData.bgPos.x, platformData.bgPos.y, this);
                this._verificBtn = UIFactory.gLoadingButton(platformData.verificBtnName, platformData.verificBtnPos.x, platformData.verificBtnPos.y, platformData.verificBtnSize.x, platformData.verificBtnSize.y, this);
                this._verificBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
                this._getGiftBtn = UIFactory.gLoadingButton(platformData.getGiftBtnName, platformData.getGiftBtnPos.x, platformData.getGiftBtnPos.y, platformData.getGiftBtnSize.x, platformData.getGiftBtnSize.y, this);
                this._getGiftBtn.configEventListener(MouseEvent.CLICK, this.onClickHandle);
                this._giftList = UIFactory.tileList(platformData.giftListPos.x, platformData.giftListPos.y, 500, 80, this);
                this._giftList.columnWidth = platformData.cellSize.x;
                this._giftList.rowHeight = platformData.cellSize.y;
                this._giftList.setStyle("cellRenderer", platformData.cellRender);
                this._giftList.direction = GBoxDirection.HORIZONTAL;
                _loc_1 = PlatformVerificUtil.getExtend();
                this._giftList.dataProvider = this.getGiftDataProviderByGiftItemCode(PlatformGiftConfig.instance.getGift(_loc_1).reward);
                this._giftList.drawNow();
                if (platformData.textInputPos)
                {
                    this._textInput = UIFactory.gTextInput(platformData.textInputPos.x, platformData.textInputPos.y, 314, 32, this);
                    this._textInput.defaultText = "在此输入激活码序列号";
                }
            }
            return;
        }// end function

        private function getGiftDataProviderByGiftItemCode(param1:int) : DataProvider
        {
            var _loc_5:Array = null;
            var _loc_6:ItemData = null;
            var _loc_9:YYZiZuanGiftDataGroup = null;
            var _loc_2:* = new DataProvider();
            var _loc_3:* = new ItemData(param1).itemInfo as ItemGiftBagInfo;
            var _loc_4:* = _loc_3.itemList1.split("&");
            var _loc_7:* = _loc_4.length;
            var _loc_8:int = 0;
            while (_loc_8 < _loc_4.length)
            {
                
                _loc_5 = _loc_4[_loc_8].split("#");
                _loc_9 = new YYZiZuanGiftDataGroup();
                _loc_9.itemCode = int(_loc_5[1]);
                _loc_9.itemAmount = _loc_5[2];
                _loc_9.isBind = true;
                _loc_2.addItem(_loc_9);
                _loc_8++;
            }
            return _loc_2;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._bg)
            {
                this._bg.dispose(param1);
                this._bg = null;
            }
            if (this._getGiftBtn)
            {
                this._getGiftBtn.dispose(param1);
            }
            if (this._verificBtn)
            {
                this._verificBtn.dispose(param1);
                this._verificBtn = null;
            }
            if (this._giftList)
            {
                this._giftList.dispose(param1);
                this._giftList = null;
            }
            if (this._textInput)
            {
                this._textInput.dispose(param1);
                this._textInput = null;
            }
            super.disposeImpl(param1);
            return;
        }// end function

        protected function onClickHandle(event:MouseEvent) : void
        {
            if (event.target == this._verificBtn)
            {
                GameUtil.gotoPlatformVerific();
            }
            else if (event.target == this._getGiftBtn)
            {
                if (this._textInput.text == "" || this._textInput.text == this._textInput.defaultText)
                {
                    MsgManager.showMouseMsg("请输入激活码序列号", MsgRollTipsType.msgRollTips2);
                    return;
                }
                GameProxy.Platform.verificCode(this._textInput.text);
            }
            return;
        }// end function

    }
}
